import http from '@/utils/http'

const BASE_URL = '/system/config'

export interface ConfigResp {
  id: string
  category: string
  code: string
  name: string
  value: string
  defaultValue: string
  description: string
}

export interface ConfigQuery extends SortQuery {
  category?: string
}

export interface ConfigCategory {
  category: string
  configCount: number
}

export function getList(category: string) {
  return http.get<ConfigResp[]>(`${BASE_URL}/list/config/${category}`)
}

export function getDetail(id: string) {
  return http.get<ConfigResp>(`${BASE_URL}/detail/${id}`)
}

export function create(data: any) {
  return http.post(`${BASE_URL}/create`, data)
}

export function update(data: any, id: string) {
  return http.post(`${BASE_URL}/update/${id}`, data)
}

export function updateConfigMap(data: Record<string, any>) {
  return http.post(`${BASE_URL}/update/map`, data)
}

export function listMapByCategory(category: string) {
  return http.get<Record<string, any>>(`${BASE_URL}/category/${category}`)
}

export function listCategory() {
  return http.get<ConfigCategory[]>(`${BASE_URL}/list/category`)
}

export function reloadConfig() {
  return http.post(`${BASE_URL}/reload`)
}

export function getNotifyConfig() {
  return http.get(`${BASE_URL}/get/properties/NotifyConfig`)
}

export function updateNotifyConfig(req: any) {
  return http.post(`${BASE_URL}/update/properties/NotifyConfig`, req)
}
